<!-- <template>
    <h1>用户登录页面</h1>

    <table>
       <tr>
            <td>用户名</td>
            <td>
                <input type="text"  v-model="info.Name" placeholder="请输入用户名">
            </td>
       </tr>

       <tr>
            <td>密码</td>
            <td>
                <input type="password" v-model="info.Pwd" placeholder="请输入密码" >
            </td>
       </tr>

       <tr>
            <td colspan="2">
                <input type="button" value="登录" @click="Login">
            </td>
       </tr>

    
    </table>

</template>

<script setup lang="ts">

import {ref} from 'vue'
import axios from 'axios';
import { useRouter } from 'vue-router';
import {useUserStore} from '../../store/index';

const router = useRouter();
const info = ref({
    Name:'',
    Pwd:''
})


const useStore = useUserStore();

const Login =()=>{
    axios({
        url:'http://localhost:56707/api/User/UserLogin',
        method:'get',
        params:{
            Name:info.value.Name,
            Pwd:info.value.Pwd
        }
    })
    .then(res=>{
        console.log(res.data);

        if(res.data.RM_Id == 1){
            alert(res.data.RM_Name);
        }
        else if(res.data.RM_Id == 2){
            alert(res.data.RM_Name);
        }
        else if(res.data.RM_Id == 0){
            //登录成功
            alert(res.data.RM_Name);
            //将用户编号保存到仓库中
            useStore.Uid = res.data.RM_Data[0].U_Id

            console.log(res.data.RM_Data[0].U_Id);

            ShowUserInfo(res.data.RM_Data[0].U_Id);
        }
        else{
            alert('登录失败');
        }


    })
    .catch(err=>{
        console.log(err)
    })
}

const ShowUserInfo = (UId:string)=>{
    axios({
        url:'http://localhost:56707/api/User/ShowUserInfo',
        method:'get',
        params:{
            UId:UId
        }
    })
    .then(res=>{
        if(res.data>0){
            //用户完善了个人信息 ，需要跳转到主页面
            alert("即将跳转到主页面");
            router.push("/BorrowShow")//跳转显示用户即将投资页面
        }
        else{
            //用户没有完善了个人信息 ，需要完善信息
            router.push({
                name:'UserRegister',
                params:{
                    U_Id:UId
                }
            })
        }
    })
    .catch(err=>{
        console.log(err)
    })
}


</script> -->


<template>

<!-- END LOGO -->
<!-- BEGIN LOGIN -->

<link rel="stylesheet" href="./src/assets/css/login.css">

<div class="pure-g content">
	<div class="pure-form pure-u-1">
        <h4>请登录您的账号</h4>
        <fieldset class="pure-group">
            <input type="text" class="pure-input-1" v-model="info.Name"  placeholder="用户名" required autofocus>
            <input type="password" class="pure-input-1" v-model="info.Pwd" placeholder="密　码" required>
        </fieldset>
		
        <button @click="Login" class="pure-button pure-u-1 pure-button-primary" >登　录</button>
	</div>
</div>
<!-- END LOGIN -->
<!--BEGIN FOOT-->
<div class="pure-g copyright">
    <div class="pure-u-1"> 2024 © 2202 asas </div>
</div>


</template>

<script setup lang="ts">

import {ref} from 'vue'
import axios from 'axios';
import { useRouter } from 'vue-router';
import {useUserStore} from '../../store/index';

const router = useRouter();
const info = ref({
    Name:'',
    Pwd:''
})


const useStore = useUserStore();

const Login =()=>{
    axios({
        url:'http://localhost:56707/api/User/UserLogin',
        method:'get',
        params:{
            Name:info.value.Name,
            Pwd:info.value.Pwd
        }
    })
    .then(res=>{
        console.log(res.data);

        if(res.data.RM_Id == 1){
            alert(res.data.RM_Name);
        }
        else if(res.data.RM_Id == 2){
            alert(res.data.RM_Name);
        }
        else if(res.data.RM_Id == 0){
            //登录成功
            alert(res.data.RM_Name);
            //将用户编号保存到仓库中
            useStore.Uid = res.data.RM_Data[0].U_Id

            console.log(res.data.RM_Data[0].U_Id);

            ShowUserInfo(res.data.RM_Data[0].U_Id);
        }
        else{
            alert('登录失败');
        }


    })
    .catch(err=>{
        console.log(err)
    })
}

const ShowUserInfo = (UId:string)=>{
    axios({
        url:'http://localhost:56707/api/User/ShowUserInfo',
        method:'get',
        params:{
            UId:UId
        }
    })
    .then(res=>{
        if(res.data>0){
            //用户完善了个人信息 ，需要跳转到主页面
            alert("即将跳转到主页面");
            router.push("/UserFinanRedeemShow")//跳转显示用户即将投资页面
        }
        else{
            //用户没有完善了个人信息 ，需要完善信息
            router.push({
                name:'UserRegister',
                params:{
                    U_Id:UId
                }
            })
        }
    })
    .catch(err=>{
        console.log(err)
    })
}

</script>